Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple async-profiler library deployments #173

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

aleks-p
Copy link
Contributor

@aleks-p aleks-p commented Dec 2, 2024

If we try to load the async-profiler library from multiple processes at the same time, loading can fail because we are trying to deploy the app multiple times.

One case where this can happen is when the SDK is used in concurrently executed unit tests.

Caused by: java.nio.file.FileAlreadyExistsException: /var/folders/rl/p7hzvh8943v6xf55qksjjc240000gn/T/redacted-pyroscope/libasyncProfiler-redacted-6bf68b96dcb6e8ec20caa84e1e69e6659f17f5.so
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:94)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:262)
	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:482)
	at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
	at java.base/java.nio.file.Files.copy(Files.java:3164)
	at io.pyroscope.labels.io.pyroscope.PyroscopeAsyncProfiler.deployLibrary(PyroscopeAsyncProfiler.java:54)
	at io.pyroscope.labels.io.pyroscope.PyroscopeAsyncProfiler.<clinit>(PyroscopeAsyncProfiler.java:25)

An alternative approach is to use Files.createTempDirectory which will result in separate deployments for each process, though in the case of unit testing this can be wasteful.

@aleks-p aleks-p requested review from a team as code owners December 2, 2024 19:03
@korniltsev
Copy link
Collaborator

Can the current implementation still trigger a race? For example one process is created and in the process of copying the library and the other process already see the library exists and tries to load it while it is still being copied?

@aleks-p
Copy link
Contributor Author

aleks-p commented Dec 3, 2024

Can the current implementation still trigger a race? For example one process is created and in the process of copying the library and the other process already see the library exists and tries to load it while it is still being copied?

You are right, I've switched to the alternative mentioned above - creating a unique temp directory.

@aleks-p aleks-p merged commit ee7458a into main Dec 4, 2024
40 checks passed
@aleks-p aleks-p deleted the patch/multiple-library-deployments branch December 4, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants